<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="议案草稿"></uni-navbar></view>

		<view class="search-view"><u-search class="search-input" shape="square" bg-color="#fff" @search="search" @custom="search"></u-search></view>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_01" v-for="(item, index) of proposeList" :key="item.id" @click="editTo(item)">
				<view class="info-title">{{ item.title }}</view>
				<view class="info-btm">
					<view class="btm-left clamp">
						<text class="left-name">{{ item.leaderName }}</text>
						<text class="left-time">{{ item.createTime | parseTime('{y}-{m}-{d}') }}</text>
					</view>
					<view class="btm-right">
						<view class="right-type" :style="'color:' + colorMap[item.nodeStatus]">{{ item.nodeStatusName || '草稿' }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			colorMap: {
				0: '#303133',
				1: '#0099ff',
				2: '#ff9900',
				3: '#19be6b',
				4: '#ff3333',
				5: '#909399',
				6: '#606266',
				7: '#b5bfff',
				8: '#fcbd71',
				99: '#71d5a1',
				100: '#fab6b6',
				101: '#c8c9cc',
				102: '#909399',
				103: '#78bbff',
				104: '#18b566',
				105: '#dd6161',
				106: '#82848a',
				107: '#c0c4cc',
				108: '#2b85e4',
				109: '#a4f1b9'
			},
			nodeStatus: 0,
			title: '',
			proposeList: [],

			motion: {
				nodeStatus: '0',
				title: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();
		if (option && option.status) {
			this.nodeStatus = option.status;
		}
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.nodeStatus == -1) {
				this.motion.nodeStatus = '';
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				currentUserId: this.userId,
				motion: this.motion
			};
			this.$request('/motion/yian/myList', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.proposeList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.proposeList = this.proposeList.concat(res.data.records);
				this.loaded = true;
				if (this.proposeList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		search(e) {
			this.motion.title = e;
			this.loadData('refresh');
		},
		type(e) {
			this.nodeStatus = e;
			this.motion.nodeStatus = e.toString();
			this.loadData('refresh');
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesB/propose/detail?id=' + item.id
			});
		},
		editTo(item) {
			uni.navigateTo({
				url: '/pagesB/propose/add?id=' + item.id + '&type=spare'
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}
</style>
